package com.zxj.friend.controller.question;


import com.zxj.common.core.contains.HttpConstants;
import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.common.core.domain.vo.PageVO;
import com.zxj.friend.domain.question.dto.QuestionPageQueryDTO;
import com.zxj.friend.domain.question.vo.QuestionDetailVO;
import com.zxj.friend.domain.question.vo.QuestionVO;
import com.zxj.friend.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 问题控制器
 * </p>
 *
 * @author zxj2022
 * @date 2024/12/26
 */
@RestController
@RequestMapping("/question")
@Tag(name = "问题管理接口", description = "问题管理相关接口")
@Slf4j
@RequiredArgsConstructor
public class QuestionController extends BaseController {
    private final IQuestionService questionService;

    @GetMapping("/semiLogin/list")
    @Operation(summary = "问题列表", description = "获取问题列表")
    public R<PageVO<QuestionVO>> pageList(QuestionPageQueryDTO questionPageQueryDTO) {
        log.info("分页查询问题列表,查询条件:{}", questionPageQueryDTO);
        return R.ok(questionService.pageList(questionPageQueryDTO));
    }

    @GetMapping("/detail")
    @Operation(summary = "依据ID获取问题详细信息", description = "依据ID获取问题详细信息")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    public R<QuestionDetailVO> detail(Long questionId) {
        log.info("查询问题详情,问题ID:{}", questionId);
        return R.ok(questionService.detail(questionId));
    }

    @GetMapping("/semiLogin/hotList")
    @Operation(summary = "热门题目列表", description = "热门题目列表")
    public R<List<QuestionVO>> hotList() {
        log.info("查询热门题目列表");
        return R.ok(questionService.hotList());
    }


    //题目的顺序列表 : 先从redis  redis中没有数据查询数据库
    // 当前题目是哪个（questionId）
    //redis  list  数据类型  key: q:l value : questionId
    @GetMapping("/preQuestion")
    @Operation(summary = "获取上一题", description = "获取上一题")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @Parameter(name = "questionId", description = "问题ID", required = true,  in = ParameterIn.QUERY)
    public R<String> preQuestion(Long questionId) {
        log.info("查询上一题,问题ID:{}", questionId);
        return R.ok(questionService.preQuestion(questionId));
    }

    @GetMapping("/nextQuestion")
    @Operation(summary = "获取下一题", description = "获取下一题")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @Parameter(name = "questionId", description = "问题ID", required = true,  in = ParameterIn.QUERY)
    public R<String> nextQuestion(Long questionId) {
        log.info("查询下一题,问题ID:{}", questionId);
        return R.ok(questionService.nextQuestion(questionId));
    }
}
